package com.fl.mybatisgenerator.demo;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 买火车票demo
 */
@Slf4j
public class demo3 implements Runnable{
    //票数
    private volatile Integer sum =10;

    public demo3(Integer sum){
        this.sum = sum;
    }

    @SneakyThrows
    @Override
    public void run() {
        while (true){
            if (sum<=0){
                break;
            }
            String name = Thread.currentThread().getName();
            log.info("线程{}购买了第:{}张票",name,sum--);
            Thread.sleep(200);
        }
    }

    public static void main(String[] args) {
        demo3 t1 = new demo3(20);
        new Thread(t1,"老魏").start();
        new Thread(t1,"刘能").start();
        new Thread(t1,"小黑").start();
    }
}
